package cn.job.j3

import scala.collection.mutable

object Case3 {

  def main(args: Array[String]): Unit = {
    val data: String =
      """UserA,LocationA,8,60
                         UserA,LocationA,9,60
                         UserB,LocationB,10,60
                         UserB,LocationB,11,80 """.stripMargin
    val dataArray: mutable.Seq[String] = data.split("\n").toBuffer

    /**
     * 通过map，记录每次
     */
    val map2: mutable.Map[String, Int] = mutable.Map()
    dataArray.foreach(line => {
      val arr = line.split(",")
      val key = arr.take(2).toBuffer.mkString(",").trim
      map2(key) = map2.getOrElse(key, 0) + arr.last.trim.toInt
    })

    map2.foreach { case (k, v) =>
      println(k, "=>", v)
    }
  }

}
